﻿/*
 * Summary:
 *   indexer for maintaining sports items and 
 *   supporting binary searching by name
 *   
 * History:
 *   Date           Author      Changes
 *   23/10/2010     YIWEI YU    Created
 */

using System;
using System.Collections;

namespace AcmeSportsStore
{
    class SportsItemIndexerByName : Indexer
    {
        public class UniquenessBasedComparer : IComparer
        {
            public int Compare(object x, object y)
            {
                SportsItem siX = (SportsItem)x;
                SportsItem siY = (SportsItem)y;

                int res = siX.Name.CompareTo(siY.Name);
                if (res == 0)
                {
                    res = siX.Id.CompareTo(siY.Id);
                }
                return res;
            }
        }

        public class FieldComparer : IComparer
        {
            public int Compare(object x, object y)
            {
                SportsItem siX = (SportsItem)x;
                SportsItem siY = (SportsItem)y;

                return siX.Name.CompareTo(siY.Name);
            }
        }

        public readonly static UniquenessBasedComparer UBComp
            = new UniquenessBasedComparer();

        public readonly static FieldComparer FComp
            = new FieldComparer();

        public SportsItemIndexerByName()
            : base(UBComp, FComp)
        {
        }
    }
}
